<?php

	class LoginView {
		
		//Private variables for use in getting the login information
		private $m_getUserName = "Username";
		private $m_getPassword = "Password";
		
		private $m_triedToLogin = "Login";
		private $m_triedToLogOut = "Logout";
		private $m_triedToSignUp = "SignUp";
		private $m_rememberMe = "RememberMe";
		
		//Skriver ut inloggningsformuläret
		public function DoLoginBox() {
			return "
		<div id='loginBox'>
			<div id='signUpBox' >
				<a id='signUp' href='?SignUp=SignUp' name='$this->m_triedToSignUp'>Sign up</a>
			</div>
			<form method='post'>
				<p>
					<label for='name'>E-mail: <input class='textBox' type='text' id='name' name='$this->m_getUserName' ></label>
				</p>
				<p>
					<label for='password'>Password: <input class='textBox' type='text' id='password' name='$this->m_getPassword' ></label>
				</p>
				<p id='rememberTag'>
					<input class='button' type='submit' value='Login' name='$this->m_triedToLogin' >
					<label for='rememberMe'>Remember me <input type='checkbox' id='rememberMe' name='RememberMe' ></label>
				</p>
			</form>
		</div>";
		}
		//Skriver ut logout-knappen
		public function DoLogoutBox(){
			return "
		<div id='logoutbox' >
			<a id='logout' href='?Logout=Logout' >Logout</a>
		</div>";
		}
		//Returnerar  html för meddelanden
		public function DoFeedback($message){
			return "
		<div id='feedback'>
			<p>$message</p>
		</div>";
		}
		//Tar hand om lösenordet
		public function GetUserName() {
      		return (isset($_POST[$this->m_getUserName]) ? $_POST[$this->m_getUserName] : NULL);
  		}
		//Tar hand om lösenordet
		public function GetPassword() {
			return (isset($_POST[$this->m_getPassword]) ? $_POST[$this->m_getPassword] : NULL);
  		}
  		
  		//Ser om login-knappen trycks ner
  		public function TriedToLogin() {
			return (isset($_POST[$this->m_triedToLogin]) ? TRUE : FALSE);
  		}
  		
  		//Ser om logout-knappen trycks ner
  		public function TriedToLogOut() {
			return (isset($_GET[$this->m_triedToLogOut]) ? TRUE : FALSE);
  		}
  		
		//Ser om sign up-knappen trycks ner
		public function TriedToSignUp() {
			return (isset($_GET[$this->m_triedToSignUp]) ? TRUE : FALSE);
		}
		
  		//Ser om användaren vill bli ihågkommen.
  		public function RememberUser() {
			return (isset($_POST[$this->m_rememberMe]) ? TRUE : FALSE);
  		}
		
		//Sparar användarnamnet i cookie.
  		public function SetCookies($userName, $password) {
  			setcookie($this->m_getUserName, $userName, time()+3600);
			setcookie($this->m_getPassword, $password, time()+3600);
  		}
		
		//Hämtar UsernameCookie
  		public function GetUsernameCookie() {
			return (isset($_COOKIE[$this->m_getUserName]) ? $_COOKIE[$this->m_getUserName] : NULL);
  		}
		
		//Hämtar PasswordCookie
  		public function GetPasswordCookie() {
  			return (isset($_COOKIE[$this->m_getPassword]) ? $_COOKIE[$this->m_getPassword] : NULL);
  		}
		
		//kollar om några cookies är satta
  		public function IsCoockiesSet() {
  			if(isset($_COOKIE[$this->m_getUserName]) && 
  					($_COOKIE[$this->m_getPassword])){
  				return TRUE;
			} else {
				return FALSE;
			}
  		}
		//kollar om dågra cookies är satta
  		public function RemoveCoockies() {
  			if(isset($_COOKIE[$this->m_getUserName]) && 
  					($_COOKIE[$this->m_getPassword])){
  					setcookie($this->m_getUserName, "", time()-3600);
					setcookie($this->m_getPassword, "", time()-3600);
			} 
  		}
	}
?>